<template>
  <div class="risk-compliance c-shadow">
    <jTabNav :items="tabList"></jTabNav>
    <div class="xwdt">
      <h4 class="detail-base-title d_jump" ref="publicOpinion1" v-show="total">新闻动态<span>{{total}}</span></h4>
      <j-no-data v-if="!total" :mode="'b'" msg="b"></j-no-data>
      <div v-else class="table-wrap">
        <table>
          <thead>
            <tr>
              <th v-for="title in writ" :key="title">{{title}}</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="item in writData" :key="item.writ">
              <td :title="item.titleShort">
                <a :href="item.textLink" target="_blank">
                  {{item.title || '--'}}
                </a>
              </td>
              <td v-if="item.sentimentType === 1">负面</td>
              <td v-else-if="item.sentimentType === 2">中面</td>
              <td v-else-if="item.sentimentType === 3">正面</td>
              <td v-else>--</td>
              <td>{{item.webSrc || '--'}}</td>
              <td>{{item.publishTm | dateFormat}}</td>
            </tr>
          </tbody>
        </table>
        <div class="block paging-wrap fr">
          <el-pagination v-if="total>10"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageNum"
            :page-size="pageSize"
            layout="prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { jTabNav, jNoData } from '../../components'
import { sysSetting as api } from '../../api'
export default {
  data() {
    return {
      tabList: [],
      writ: ['新闻标题', '倾向', '来源', '时间'],
      writData: [],
      xwdt: 0,
      params: {},
      pageNum: 1,
      pageSize: 10,
      total: 0,
      number: '',
      entId: ''
    }
  },
  mounted() {
    this.params.entName = this.$route.query.entname
    this.getRealTimeDataPublicSentimentList()
  },
  methods: {
    // 获取新闻动态
    getRealTimeDataPublicSentimentList() {
      let _this = this
      let params = {
        pageNum: _this.pageNum,
        pageSize: _this.pageSize
      }
      api
        .getRealTimeDataPublicSentimentList({ ..._this.params, ...params })
        .then(rtn => {
          console.log(rtn)
          _this.writData = rtn.data.list
          _this.total = rtn.data.total
          if (!_this.xwdt) {
            _this.tabList.push({
              idx: 1,
              name: '新闻动态',
              num: rtn.data.total,
              offsetTop: this.$refs['publicOpinion1'].offsetTop
            })
          }
          ++_this.xwdt
        })
        .catch(err => {
          _this.pageState = err
        })
    },
    handleSizeChange() {
      // 当pagesize改变的时候出发该函数
    },
    handleCurrentChange(index) {
      this.pageNum = index
      this.getRealTimeDataPublicSentimentList()
    }
  },
  components: {
    jNoData,
    jTabNav
  }
}
</script>
<style lang="scss" scoped>
.risk-compliance {
  a {
    text-decoration: none;
  }
  padding: 28px 40px;
  font-size: 14px;
  .detail-base-title {
    line-height: 30px;
    font-size: 16px;
    font-weight: bold;
    padding: 30px 0 0 12px;
    position: relative;
    background-image: linear-gradient(0deg,#1891ef,#1891ef);
    background-size: 3px 16px;
    background-position: 0 37px;
    background-repeat: no-repeat;
    border-bottom: 1px solid #eee;
  }
  h4.detail-base-title span {
    border: 1px solid #9dc5fd;
    border-radius: 10px;
    color: #1688f3;
    background: #f2f7ff;
    font-size: 12px;
    padding: 0 10px;
    margin-left: 15px;
    vertical-align: top;
  }
  .table-wrap {
    padding: 30px 20px;
    table {
      border-collapse: collapse;
      width: 100%;
      text-align: center;
      tr:hover {
        background: #f3f8ff;
      }
      td,
      th {
        border: 1px solid #e2e2e2;
        line-height: 36px;
      }
      th {
        line-height: 40px;
        color: #999;
        background: #f2f1f1;
      }
      th:nth-child(2),
      th:nth-child(3),
      th:nth-child(4) {
        width: 200px;
      }
      td {
        padding: 3px 2px;
      }
    }
  }
}
</style>



// WEBPACK FOOTER //
// src/view/clib/publicOpinion.vue